<template>
  <div class="learn">
    <div class="block">
      <el-card class="box-card" :body-style="{backgroundColor: '#fafafa' }">
        <div slot="header" class="box-head">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item class="c-text">
              防诈学习
            </el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <el-row :gutter="50">
          <el-col :span="12">
            <div class="per">
              <el-progress class="pro" type="circle" :stroke-width="8" :width="200"
                           :percentage="Math.round(this.right/this.num * 10000) / 100"></el-progress>
              <span>练习正确率<br>（{{this.right}}/{{this.num}}）</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="per">
              <el-progress class="pro" type="circle" :stroke-width="8" :width="200"
                           :percentage="Math.round(this.num/this.total * 10000) / 100"></el-progress>
              <span>题目练习率<br>（{{this.num}}/{{this.total}}）</span>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="50">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-card class="b-card" :body-style="{ padding: '0px',}" shadow="hover" @click.native="cardclick(1)">
                <div class="b-text">
                  <span>题目练习</span>
                </div>
              </el-card>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-card class="b-card" :body-style="{ padding: '0px' }" shadow="hover" @click.native="cardclick(2)">
                <div class="b-text">
                  <span>情景测试</span>
                </div>
              </el-card>
            </div>
          </el-col>
        </el-row>
      </el-card>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data : function() {
    return {
      total: '0',
      num: '0',
      right: '0',
      numper: '100',
    }
  },
  mounted() {
    this.load();
  },
  methods: {
    load() {
      if(!sessionStorage.getItem("user")){
        this.$message({
          type: 'error',
          showClose: true,
          message: '您还未登录，请登陆查看学习信息！'
        });
        this.$router.push("/login")//页面跳转
      }
      else {
        let users = JSON.parse(sessionStorage.getItem("user"))
        axios.get("api/question/info/count").then((res) => {
          // 获取题目总数
          if (res.data.code === '0') {
            // 成功从后端获取返回信息
            this.total = res.data.data
            // 读取后端返回数据
          } else {
            // 后端请求数据失败
            this.$message({
              showClose: true,
              type: "error",
              message: "题目信息获取失败！"
            })
            // 返回失败信息
          }
        })
        axios.get("api/record/info/count/byuid", {
          params: {
            uid: users.id,
          }}).then((res) => {
          // 获取用户答题记录
          if (res.data.code === '0') {
            // 成功从后端获取返回信息
            this.num = res.data.data[0]
            this.right = res.data.data[1]
            // 读取后端返回数据
            } else {
            // 后端请求数据失败
            this.$message({
              showClose: true,
              type: "error",
              message: "题目信息获取失败！"
            })
            // 返回失败信息
          }
        })
      }
    },
    cardclick(id) {
      if(id === 1) {
        this.$router.push("/learn/question")
      }
      else if(id === 2){
        this.$router.push("/learn/scenechoose")
      }
    }
  }

}
</script>

<style scoped>
.learn{
  width: 100%;
  min-height: 666px;
}

.block{
  width: 80%;
  padding-top: 20px;
  position: relative;
  left: 50%;
  transform: translate(-50%, 0%);
  /*box-shadow: 0 0 8px rgba(0, 0, 0, 0.6);*/
}

.per {
  width: 200px;
  padding-top: 60px;
  padding-bottom: 60px;
  position: relative;
  left: 50%;
  transform: translate(-50%, 0%);
}

.pro {
  height: 200px !important;
  width: 200px !important;
}


.el-row {
  padding: 20px;
}

.el-col {
  border-radius: 40px;
}

.box-card{
  background-color: #354e66;
}

/deep/ .el-breadcrumb__inner {
  color: #f9bf4b !important;
  font-weight: bold !important;
}

.c-text {
  font-size: 17px;
  color: #f9bf4b;
}

.b-card {
}

.image {
  width: 100%;
  display: block;
}

.b-text {
  padding: 14px;
  background: #354e66;
  color: #f9bf4b;
  font-size: 17px;
  font-weight: bold;
}

.clearfix:after {
  clear: both
}

</style>